package javaJob.exercise.primary.array;

public class primary1 {
    public static void main(String[] args) {
        int[] nums = {1,1,2};
        int[] expectedNums = {1,2};

        int[] nums0 = {0,0,1,1,1,2,2,3,3,4};
        int[] expectedNums0 = {0,1,2,3,4};

        System.out.println("调用函数");
        int k = removeDuplicates(nums0);

        System.out.println("判断");
        assert k==expectedNums0.length;

        for (int i=0;i<k;i++){
            System.out.println("判断"+i);
            assert nums[i]==expectedNums[i];
            System.out.println(k);
        }
    }
    static int removeDuplicates(int[] nums){
        int k=0;
        for (int i=0;i<nums.length;i++){

            System.out.println("第一层循环"+i);

            for (int j=i+1;j<nums.length;j++){

                System.out.println("第二层循环"+j);
                System.out.println("nums[i]:"+nums[i]);
                System.out.println("nums[j]:"+nums[j]);

                if (nums[i]==nums[j]){
                    while (nums[i]==nums[j]){
//                        System.out.println("进入循环");
//                        nums[l]=nums[l+1];
//                        System.out.print("nums[l]:"+nums[l]);
//                        System.out.println(" ");
//                        l=l+1;
//                        if (l==nums.length-1){
//                            System.out.println("当前l："+l);
//                            break;
//                        }
                        if (nums[j]==nums[nums.length-1]){
                            break;
                        }
                        for (int l=j+1;l<nums.length;l++){
                            nums[l-1]=nums[l];
                        }
                    }
//                    for (int l=j+1;l<nums.length;l++){
//                        System.out.println("第三层循环"+l);
//                        nums[l-1]=nums[l];
//                        if (nums[i]==nums[l-1]){
//
//                        }
//                    }
                }

            }
        }
        for (int h=0;h<nums.length;h++){
            System.out.println("最后循环"+h);
            if (nums[h]!=nums[nums.length-1]){
                k=k+1;
            }
        }
        k=k+1;
        System.out.print("{");
        for (int y=0;y<nums.length;y++){
            System.out.print(nums[y]);
        }
        System.out.println("}");
        return k;
    }

}


//标准答案
//class Solution {
//    public int removeDuplicates(int[] nums) {
//        int a=1;
//        for(int i=0;i<nums.length-1;i++){
//            if(nums[i]!=nums[i+1]){
//                nums[a]=nums[i+1];
//                a++;
//            }
//        }
//        return a;
//
//    }
//}